<template>
	<view class="container">
		<view class="waimai-head">
			<image src="../../static/head-waimai.png" class="img"></image>
		</view>
		<view class="waimai-main flex-column">
			<view
				style="height: 1.8rem; display: flex; align-items: center;font-weight: bold;font-size: 23px;align-self: center;">
				免费领取外卖随机红包</view>
			<view v-if="!isNull(systemShare.integralFlag) && systemShare.integralFlag"
				style="margin-top: 0.4rem; height: 1.8rem; display: flex; align-items: center;align-self: center;font-size: 20px;font-weight: bold;">
				<span>送</span><span style="color: rgb(249, 169, 2);">美团</span>/<span
					style="color: rgb(6, 180, 252);">饿了么</span><span>会员月卡</span>
			</view>
			<view v-if="!isNull(systemShare.integralFlag) && systemShare.integralFlag" class="swiper-btn"
				style="border: 1px solid rgb(255, 199, 5);">美团含五元无门槛红包 × 6</view>
			<view v-if="!isNull(systemShare.integralFlag) && systemShare.integralFlag" class="swiper-btn"
				style="border: 1px solid rgb(6, 180, 252);">饿了么含五元无门槛红包 × 4</view>
		</view>
		<!-- <button @click="clear()">
			清空
		</button> -->
		<view class="waimai-quan flex-row">
			<view class="waimai-kapian flex-column" v-for="(waimai,index) in waiMaiQuans" :key="waimai.id">
				<image :src="waimai.type == 'ele' ? '../../static/ele.png' : '../../static/mt.png'" class="img"></image>
				<view>{{waimai.type == 'ele' ? '饿了么' : '美团'}}</view>
				<view>{{waimai.title}}</view>
				<view :class="['got-quan',waimai.type == 'ele' ? 'ele' : 'mt']" @click="toPath(waimai)">立即领取</view>
			</view>
		</view>
		<view class="waimai-plan flex-row">
			<view class="share-user">
				<button open-type="share">
					分享好友<u-icon name="share"></u-icon>
				</button>
			</view>
			<!-- <view class="share-user">分享好友 <u-icon name="share"></u-icon>
			</view> -->
			<view class="eat-what" @click="eatWhat()">吃啥呢 <u-icon name="question"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//吃饭提醒
				notice: false,
				//外卖券
				waiMaiQuans: [],
				//系统信息
				systemShare: {}
			}
		},
		onLoad(option) {
			this.systemShare = uni.getStorageSync("systemShare");
			if (!this.isNull(option.userId)) {
				uni.setStorageSync("inviteUserId", option.userId);
				this.boundParentUser(option.userId);
			}
		},
		onShow() {
			this.loadWaiMai();
			this.systemShare = uni.getStorageSync("systemShare");
		},
		methods: {
			//提醒明天吃饭
			changeNotice(e) {
				if (e) {
					this.$u.get('/waiMai/notice').then(res => {
						this.notice = e;
					});
				}
			},
			//清理缓存
			clear() {
				uni.clearStorageSync();
			},
			//跳转吃啥页
			eatWhat() {
				uni.navigateTo({
					url: '../eatWhat/eatWhat'
				})
			},
			//跳转其他小程序
			toPath(weiMai) {
				const _this = this;
				uni.navigateToMiniProgram({
					appId: weiMai.appId,
					path: weiMai.path,
					success(res) {
						console.log(res)
						_this.addWaiMaiUserReceive(weiMai.id);
					}
				})
			},
			//加载外卖数据
			loadWaiMai() {
				this.$u.get(`/waiMai/list/${this.systemId}`).then(res => {
					this.waiMaiQuans = res.data;
				});
			},
			//添加用户领取记录,并通知系统用户
			addWaiMaiUserReceive(waiMaiId) {
				this.$u.post('/waiMaiUserReceive/add', {
					waiMaiId: waiMaiId
				}).then(res => {
					console.log(res)
				});
			},
			//uniapp微信小程序分享页面到微信朋友圈
			onShareTimeline() {
				const share = this.getShareInfo();
				this.shareApp();
				return share;
			},
			//分享好友
			onShareAppMessage(res) {
				const share = this.getShareInfo();
				this.shareApp();
				return share;
			},
			//分享小程序
			shareApp() {
				if (this.systemShare.integralFlag) {
					this.$u.get(`/waiMai/share`).then(res => {});
				}
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f5f5f5;
		padding: 0px 15px 15px 15px;
		box-sizing: border-box;
	}

	.waimai-head {
		height: 80px;
		display: flex;
		justify-content: space-evenly;

		.img {
			height: 100%;
			display: block;
			width: 75%;
		}
	}

	.waimai-main {
		background-color: #FFFFFF;
		padding: 15px;
		border-radius: 6px;
		margin-bottom: .8rem;

		.swiper-btn {
			margin-top: .6rem;
			border-radius: 1.4rem;
			font-size: .8rem;
			font-weight: 400;
			padding: .2rem .8rem;
			border: 1px solid #06b4fc;
			text-align: center;
			font-weight: bold;
		}

	}

	.waimai-alarm {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #fff;
		box-shadow: 0 1px 4px 0 rgba(0, 0, 0, .06);
		border-radius: 6px;
		box-sizing: border-box;
		padding: .6rem 1rem;
		margin-bottom: .8rem;
	}

	.waimai-quan {
		flex-wrap: wrap;
		justify-content: space-between;

		.waimai-kapian {
			width: 49%;
			background-color: #FFF;
			padding: 10px;
			margin-bottom: .5rem;
			align-items: center;
			box-shadow: 0 1px 4px 0 rgba(0, 0, 0, .06);
			border-radius: 6px;

			.img {
				width: 65px;
				height: 65px;
				margin-bottom: 5px;
			}

			.got-quan {
				width: 120px;
				height: 32px;
				margin: 0 auto;
				box-sizing: border-box;
				border-radius: 18px;
				line-height: 32px;
				text-align: center;
				font-size: 1rem;
				font-weight: 500;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-top: 10px;
			}

			.mt {
				color: #fec509;
				border: 2px solid #fec509;
			}

			.ele {
				color: #1a85f7;
				border: 2px solid #1a85f7;
			}
		}
	}

	.waimai-plan {
		border-radius: 6px;
		flex-wrap: wrap;
		justify-content: space-between;
		font-size: 16px;


		.share-user {
			width: 49%;
			display: block;
			border: 2px solid #FFFFFF;
			background-color: #FFFFFF;
			border-radius: 6px;
			text-align: center;
			padding: 10px;
			box-sizing: border-box;
			font-weight: bold;
			box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.06);

			button {
				background-color: #FFFF;
				height: 100%;
				line-height: 20px;
				font-size: 16px;
			}

			button::after {
				border: 0px solid #FFFFFF;
				align-items: center;
				align-content: center;
			}
		}

		.eat-what {
			width: 49%;
			display: block;
			border: 2px solid #FFFFFF;
			background-color: #FFFFFF;
			border-radius: 6px;
			text-align: center;
			padding: 10px;
			box-sizing: border-box;
			font-weight: bold;
			box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.06);
		}
	}
</style>
